import { connect } from 'react-redux'
import { toggleTodo } from '../actions/actions'
import { TodoList } from '../components/TodoList'
import { getVisibleTodos } from '../reducers/todos'
import * as actions from '../actions/actions'
import { withRouter } from 'react-router-dom'
/*
connect(
  stateMapProps, // (state, ownProps) => props
  dispatchMapProps // (dispatch, ownProps) => props
)(Component)
*/

export const VisibleTodoList = withRouter(
  connect(
    // 把state转换成props,
    (state, ownProps) => {
      // console.log(ownProps)
      return {
        todos: getVisibleTodos(
          state.todos,
          ownProps.match.params.filter || 'all'
        ),
      }
    },
    // 把dispatch转化成props
    actions
  )(TodoList)
)
